"""
@Use: This program is used to create a matrix 150.41 sites in following format
initial1, migrated1
initial2, migrated2
...
initial n, migrated n
"""

import MySQLdb
import csv 

#"""

database = "isec2014"
user = "root"
password="123"
port=3306
table = "qimp_vote_rep"
file_path = "D:\Research\ISEC-2014\data\Result2_q36_124_41_quest.csv"

#table = "124_41_site_from_migration_aug13"
#file_path = "D:\Research\ISEC-2014\data\matrix1_q36_124_41.csv"
"""

database = "sangeeta"
user = "sangeetal"
password="sangeetal"
port=3307
table = "qimp_vote_rep"
file_path = "D:\Research\ISEC-2014\data\Result2_q36_124_41_quest.csv"
table = "124_41_site_from_migration_aug13"
file_path = "E:\sangeeta\matrix1_q36_124_41.csv"
#"""


fo = open(file_path, 'wb')
filewriter = csv.writer(fo, delimiter=',', quotechar=' ', quoting=csv.QUOTE_MINIMAL)

db1= MySQLdb.connect(host="localhost", user=user, passwd=password,db=database, port=port)
select_cursor = db1.cursor()

select_q = "select initial, migrated from " + table

select_cursor.execute(select_q)
rows = select_cursor.fetchall()

count = 0
for row in rows:
    line = list()
    count = count+1
    print count 
    initial = row[0].strip().replace(".stackexchange","")
    migrated = row[1].strip().replace(".stackexchange","")
    line.append(initial)
    line.append(migrated)
    filewriter.writerow(line)
    
    
fo.close()    